package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permisssionDao;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();//页码
        Integer pageSize = queryPageBean.getPageSize();//每页显示条数
        String queryString = queryPageBean.getQueryString();//查询条件
        PageHelper.startPage(currentPage,pageSize);
        //按条件查询出来封装成list集合
        List<Permission> permissionList = permisssionDao.selectByCondition(queryString);
        PageInfo pageInfo = new PageInfo(permissionList);
        long total = pageInfo.getTotal();
        List pageInfoList = pageInfo.getList();
        //PageResult里面封装的是总页数，查询出来的结果
        return new PageResult(total,pageInfoList);
    }

    @Override
    public void add(Permission permission) {
         permisssionDao.add(permission);
    }

    @Override
    public Permission findById(Integer id) {
        return permisssionDao.findById(id);
    }

    @Override
    public void edit(Permission permission) {
        permisssionDao.edit(permission);
    }

    @Override
    public void deleteById(Integer id) {
        permisssionDao.deleteById(id);
    }

    @Override
    public List<Permission> findAll(){
        return permisssionDao.findAll();
    }
}
